﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QASampling.Util
{
    class StringUtil
    {        
        public static string ConvertToString(string[] stringarray)
        {
            string ret = string.Join(",", stringarray.ToArray());
            return ret;
        }

        public static string ConvertToString(List<string> stringlist)
        {
            string ret = string.Join(",", stringlist.ToArray());
            return ret;
        }

        public static string ConvertToParamString(string[] stringarray)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < stringarray.Length; i++)
            {
                sb.Append(":P" + i);
                sb.Append(",");
            }
            sb = sb.Remove(sb.Length - 1, 1);
            return sb.ToString();
        }

        public static string ConvertToCompareParamString(string[] stringarray, string comparer, string delimiter)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < stringarray.Length; i++)
            {
                sb.Append(stringarray[i]);
                sb.Append(comparer);
                sb.Append(":P" + i);
                if (i != stringarray.Length - 1)
                    sb.Append(delimiter);
            }
            return sb.ToString();
        }

        public static string ConvertToCompareParamString(string[] stringarray, string comparer)
        {
            StringBuilder sb = new StringBuilder();            
            for (int i = 0; i < stringarray.Length; i++)
            {
                sb.Append(stringarray[i]);
                sb.Append(comparer);
                sb.Append(":P"+i);
                if (i!=stringarray.Length-1)
                    sb.Append(" AND ");
            }
            return sb.ToString();
        }

        internal static string WrapMessage(string sWarp, int wraplength)
        {
            StringBuilder sb = new StringBuilder(sWarp);
            int index = 0;
            int i = 1;
            while (index < sb.Length)
            {
                index = wraplength * i++;
                if (index < sb.Length)
                    sb.Insert(index, Environment.NewLine);
            }

            return sb.ToString();
            
        }
    }
}
